package com.zhuqi;

import org.activiti.engine.*;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.jupiter.api.Test;

import java.util.HashMap;

/**
 * @author : ZhuQi
 * @version : 时间:2022/3/21 16:29 版本:
 * 测试并行网关
 */
public class ActivitiTestDemo04 {

    private ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();


    /**
     * 测试内容: 流程部署
     * 测试结果:
     */
    @Test
    public void test() throws Exception {
        RepositoryService repositoryService = processEngine.getRepositoryService();

        Deployment deploy = repositoryService.createDeployment()
                .addClasspathResource("bpmn/eveection-parallel.bpmn")
                .addClasspathResource("bpmn/eveection-parallel.png")
                .name("eveection-并行网关")
                .deploy();
        System.out.println(deploy.getId());
        System.out.println(deploy.getName());
        System.out.println(deploy.getKey());
    }


    /**
     * 测试内容: 启动流程实例
     * 测试结果:
     */
    @Test
    public void test01() throws Exception {
        RuntimeService runtimeService = processEngine.getRuntimeService();
        HashMap<String, Object> data = new HashMap<>();

        data.put("user0", "张三");
        data.put("user1", "李四");
        data.put("user2", "王五");
        data.put("user3", "赵六");
        data.put("user4", "田七");
        data.put("user5", "猪八");
        data.put("day", "5");

        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("eveection-para", "123", data);

        System.out.println(processInstance.getId());
        // 77501
        System.out.println(processInstance.getName());
    }

    /**
     * 测试内容: 测试完成任务
     * 测试结果:
     */
    @Test
    public void test02() throws Exception {
        String assignee = "赵六";
        TaskService taskService = processEngine.getTaskService();
        Task task = taskService.createTaskQuery().processInstanceId("77501")
                .taskAssignee(assignee).singleResult();
        if (task != null) {
            System.out.println("任务ID" + task.getId());
            System.out.println("任务名" + task.getName());
            taskService.complete(task.getId());
        } else {
            System.out.println(assignee + "没有任务");
        }
    }
}
